//
// Created by bxw57 on 2024/6/15.
//
#include <iostream>
#include <thread>
#include <mutex>

std::mutex mtx; // 全局互斥锁

void printBlock(int n) {
    mtx.lock(); // 获取互斥锁

    for (int i = 0; i < 5; ++i) {
        std::cout << "Thread " << n << " is printing " << i << std::endl;
    }

    mtx.unlock(); // 释放互斥锁
}

int main() {
    std::thread t1(printBlock, 1);
    std::thread t2(printBlock, 2);

    t1.join();
    t2.join();

    return 0;
}
